(function ($app) {
    $app.module('gtPartyApp').controller('mutualScoreCtrl', function ($scope, $http, $modal, $ocLazyLoad, $alert, $loading, $state, AuthUser, $window, $partySelect, $stateParams, $bsRouterState, $partySelect) {
        $stateParams = $bsRouterState.$params($scope);
        $scope.isDetail = $stateParams.recordStatus!=3;
        //定义数据集合
        $scope.dataModel = {
            arrangeid: $stateParams.id == undefined ? "" : $stateParams.id
        };
        $scope.dzzdm = $stateParams.dzzdm == undefined ? AuthUser.getUser().DPCode : $stateParams.dzzdm;
        //保存
        $scope.submitData = function (isflag) {
            if (isflag) {
                var filterDate = $scope.scorePartyList.filter(function (item) {
                    return item.score < 0 || item.score > 100;
                });
                if (filterDate.length > 0) {
                    $scope.showMsg('提示', "评分只能0-100之间");
                    return;
                }
                $loading.show();
                $http({
                    method: "post",
                    url: "../../api/examine/score/saveReview",
                    data: {
                        arrangeId: $scope.dataModel.arrangeid,
                        checkType: 1,
                        reviewList: $scope.scorePartyList
                    }
                }).then(function (result) {
                    $loading.hide();
                    $scope.showMsg('提示', result.data.msg);
                    if (result.data.success) {
                        $scope.$emit("tabReloadData", {name: 'checkScoreListCtrl', data: 1});
                        //重新刷新列表
                        $scope.pagechange();
                    }
                }, function (resp) {
                    $scope.showMsg('错误', '服务器错误');
                })
            }
        };

        $scope.loadData = function () {
            $http.get("../../api/examine/arrange/getArrange", {
                params: {
                    'arrangeId': $scope.dataModel.arrangeid,
                }
            }).then(function (result) {
                $scope.dataModel = result.data.item;
                $scope.arrangeTitle = "主题：" + $scope.dataModel.title;
            }, function () {
                $scope.showMsg('错误', '服务器错误');
            });
        };

        //加载数据
        $scope.loadData();

        $scope.scorePartyList = [];
        $scope.getScorePartyList = function () {
            $http({
                method: 'get',
                url: '../../api/examine/score/getScorePartyList',
                params: {arrangeId: $stateParams.id, dzzdm: $scope.dzzdm}
            }).then(function (result) {
                $scope.scorePartyList = result.data.item;
            }, function (resp) {

            });
        };
        $scope.getScorePartyList();

        $scope.downfile = function (id) {
            $window.open("../../api/home/downloadFile/" + id);
        }
        $scope.invalidFee = function (index, form1, name) {
            name = name + "_" + index;
            eval('var i=form1.' + name + '.$invalid');
            return i;
        };

        $scope.pagechange = function () {
            var inTab = $bsRouterState.$getRouteType() == 'tab';
            if (inTab) {
                $bsRouterState.$closeTab($scope);
            } else {
                window.history.back();
            }
        };

        $scope.showMsg = function (title, content) {
            $alert({
                title: title + '：',
                content: content,
                placement: 'top',
                type: 'info',
                show: true,
                duration: 3
            });
        };
    });
})(angular);
